----------------------------------------------------------------------------------------------------------------------------------
--[[

    finiteuses 的复制体，用来 把官方的 finiteuses 的数据表，复制到自己的数据表里 并下发 client

]]--
----------------------------------------------------------------------------------------------------------------------------------
---
    local function GetReplica(self)
        return self.inst.replica.hutao_com_finiteuses or self.inst.replica._.hutao_com_finiteuses
    end
    local function set_max(self,value)
        local replica = GetReplica(self)
        if replica then
            replica:SetMax(value)
        end
    end
    local function set_current(self,value)
        local replica = GetReplica(self)
        if replica then
            replica:SetCurrent(value)
        end
    end
----------------------------------------------------------------------------------------------------------------------------------
local hutao_com_finiteuses = Class(function(self, inst)
    self.inst = inst

    self.total = 100
    self.current = 100


    self.inst:DoTaskInTime(0,function()
        local official_finiteuses = inst.components.finiteuses
        if official_finiteuses == nil then
            return
        end
        self.total = official_finiteuses.total
        self.current = official_finiteuses.current
        --- 批量hook
        local empty_fn = function()        end
        local old_api = {
            ["SetMaxUses"] = empty_fn,
            ["SetUses"] = empty_fn,
            ["Use"] = empty_fn,
            ["SetPercent"] = empty_fn,
            ["Repair"] = empty_fn,
        }
        for api_name, fn in pairs(old_api) do
            old_api[api_name] = official_finiteuses[api_name]
        end

        local new_api = {}
        for api_name, fn in pairs(old_api) do
            new_api[api_name] = function(official_finiteuses, ...)
                local old_ret = {old_api[api_name](official_finiteuses, ...)}
                self.total = official_finiteuses.total
                self.current = official_finiteuses.current
                return unpack(old_ret)
            end
        end
        for api_name, v in pairs(new_api) do
            official_finiteuses[api_name] = new_api[api_name]
        end

    end)



end,
nil,
{
    total = set_max,
    current = set_current,
})
------------------------------------------------------------------------------------------------------------------------------
--
    function hutao_com_finiteuses:GetCurrent()
        return self.current
    end
    function hutao_com_finiteuses:GetMax()
        return self.total
    end
    function hutao_com_finiteuses:GetPercent()
        return self.current / self.total
    end
------------------------------------------------------------------------------------------------------------------------------
return hutao_com_finiteuses







